import Vue from 'vue'
import App from './App.vue'

Vue.config.productionTip = false


import {
  Button,
  Tabbar,
  TabbarItem,
  Search,
  Swipe,
  SwipeItem,
  Sidebar,
  SidebarItem,
  GoodsAction, GoodsActionIcon, GoodsActionButton,
  Grid, GridItem,
  CouponCell, CouponList,
  Icon,
  List,
  PullRefresh,
  NavBar,
  SwipeCell,
  Card,
  Checkbox, CheckboxGroup,
  Col, Row,
  SubmitBar,
  Tag,
  AddressList,
  AddressEdit,
  Area,
  Popup,
  Form,
  Field,
  Toast
} from 'vant';
Vue.use(Button);
Vue.use(Tabbar);
Vue.use(TabbarItem);
Vue.use(Search);
Vue.use(Swipe);
Vue.use(SwipeItem);
Vue.use(Sidebar);
Vue.use(SidebarItem);
Vue.use(GoodsAction);
Vue.use(GoodsActionButton);
Vue.use(GoodsActionIcon);
Vue.use(Grid);
Vue.use(GridItem);
Vue.use(CouponCell);
Vue.use(CouponList);
Vue.use(Icon);
Vue.use(List);
Vue.use(PullRefresh);
Vue.use(NavBar);
Vue.use(SwipeCell);
Vue.use(Card);
Vue.use(Checkbox);
Vue.use(CheckboxGroup);
Vue.use(Col);
Vue.use(Row);
Vue.use(SubmitBar);
Vue.use(Tag);
Vue.use(AddressList);
Vue.use(AddressEdit);
Vue.use(Area);
Vue.use(Popup);
Vue.use(Form);
Vue.use(Field);
Vue.use(Toast);

import img from '@/utils/img'
Vue.prototype.$img = img
import api from '@/api'
Vue.prototype.$api = api

import router from '@/router/index'
import store from '@/store/index'

// 自定义一个授权检验指令
Vue.directive('auth', function (el) {
  const token = store.state.user.token
  if (!token) {
    el.style.position = 'relative'
    const oDiv = document.createElement('div')
    oDiv.style.position = 'absolute'
    oDiv.style.top = 0
    oDiv.style.bottom = 0
    oDiv.style.left = 0
    oDiv.style.right = 0
    oDiv.style.zIndex = 999
    oDiv.addEventListener('click', function () {
      router.push('/login')
    })
    el.appendChild(oDiv)
  }
})

Vue.directive('scroll', function (el) {
  el.style.position = 'absolute'
  el.style.top = 0
  el.style.bottom = 0
  el.style.left = 0
  el.style.right = 0
  el.style.overflow = 'scroll'
})


new Vue({
  render: h => h(App),
  router,
  store
}).$mount('#app')
